<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;

class RaffleRecord extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\RaffleRecord';

    //关联模型
    protected array $hasOne = ['user'];

    //自定义方法排序
    protected array $sort = ['id' => 'desc'];

    public function index(): string
    {
        return Builder::Table()
            ->addColumn(['field' => 'id', 'title' => 'ID', 'sort' => true, 'width' => 80])
            ->addColumn(['field' => 'uid', 'title' => '抽奖会员', 'templet' => '#_userTpl', 'width' => 240])
            ->addColumn(['field' => 'title', 'title' => '奖品名称'])
            ->addColumn(['field' => 'amount', 'title' => '金额'])
            ->addColumn(['field' => 'create_time', 'title' => '抽奖时间'])
            ->addSearch([
                ['uid', '会员编号/昵称/手机号', 'input,Like', '', '\app\common\model\User', 'code|nickname|mobile,id']
            ])
            ->fetch();
    }
}